home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 209 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: stuart.hayes@baesema.co.uk
  3. Newsgroups: comp.lang.c
  4. Subject: Re: qsort help
  5. Date: Wed, 03 Jan 1996 11:18:33 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4cdomq$jgt@dub-news-svc-5.compuserve.com>
  8. References: <4ccio7$7c0@charm.magnus.acs.ohio-state.edu>
  9. NNTP-Posting-Host: ad05-010.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu) wrote:
  13.  
  14. >Hi, I am having some problems with the qsort routine.
  15.  
  16.  
  17. >int (*compar)(int *a, int *b)
  18. Function declaration should be:
  19. int compar(int *a, int *b)
  20. Should also declare function in header file or top of source for
  21. completeness
  22. >{
  23. >  if (*a < *b) return -1;
  24. >  else if (*a == *b) return 0;
  25. >  else return 1;
  26. >}
  27.  
  28.  
  29. Alternatively to declaring function in header file could just declare
  30. in the function below:
  31. >int return_moved_contour(int ix, int iy)
  32. >{
  33. int (*compar)(int *a, int *b);
  34. >  int i, ac, count=0;
  35. >  int y_coord[10]; /* stores y coordinates whose x == ix */
  36.  
  37. >  for (ac=0; ac<areaindex; ac++)
  38. >    {
  39. >      for (i=0; i<index[ac]; i++)
  40. >    {
  41. >      if (xpos[ac][i] == ix) y_coord[count++] = ypos[ac][i];
  42. >    }
  43. >      if (count == 0) continue; /* not in this contour */
  44. >      else {
  45. >    qsort(y_coord, count, sizeof(int), compar);
  46. >    i = 0;
  47. >    while (i<count/2) {
  48. >      if ((y_coord[i] <= iy) && (y_coord[i+1] >= iy))
  49. >        return ac;
  50. >      else i+=2;
  51. >    }
  52. >      }
  53. >    }
  54. >  return -1; /* cursor not within a contour, no response will be generated */
  55. >}
  56.  
  57. >When I tried to compile, an error was generated: 
  58. >    Error: try.c, line 791: compar must have function type
  59.  
  60. >I doublechecked the man page of qsort but still can't figure out what's
  61. >wrong.
  62.  
  63. >Could someone give me a hand here?
  64.  
  65. >Thanks.
  66.  
  67. >Xiaoyi
  68.  
  69. This is a first preliminary stab at this, haven't tried it.
  70. Hope of some help.
  71.  
  72.  
  73. Stuart
  74.  
  75.